package y;

import java.io.*;
import java.util.*;

public class EG {
    public static void main(String[] args) {
        File file = new File("C:/Users/姚明达/Desktop/111.txt");
        Scanner sc = null;
        try {
            sc = new Scanner(file);
            sc.useDelimiter("[^0-9.]+");
            double SUM = 0;
            int COUNT = 0;
            while (sc.hasNextDouble()) {
                double Price = sc.nextDouble();
                COUNT++;
                SUM += Price;
                double aver = SUM / COUNT;
                System.out.println(Price);
            }
            double aver = SUM / COUNT;
            String str = String.format("%d", (int)aver);
            int averInt = (int)Math.round(aver);
            System.out.println("平均价格：" + averInt);
            FileWriter fw = new FileWriter(file, true);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write("平均价格: " + str + " /台\n");
            bw.close();
        } catch (Exception exp) {
            System.out.println(exp);
            }
        }
    }